"use strict";

const Controller = require("egg").Controller;

class GoodsController extends Controller {
  // 列表查看
  async goodsList() {
    const { ctx } = this;
    const { pageIndex, pageSize, flagqqq } = ctx.request.body;
    const sqlData = await ctx.service.goods.goodsList(
      pageIndex,
      pageSize,
      flagqqq
    );
    ctx.body = {
      code: 200,
      list: sqlData,
      total: sqlData.length,
    };
  }
  // add
  async goodsAdd() {
    const { ctx } = this;
    const { name } = ctx.request.body;
    await ctx.service.goods.goodsAdd(name);
    ctx.body = {
      code: 200,
      msg: "添加成功",
    };
  }
  // del
  async goodsDel() {
    const { ctx } = this;
    const { id } = ctx.query;
    await ctx.service.goods.goodsDel(id);
    ctx.body = {
      code: 200,
      msg: "删除成功",
    };
  }
  // set
  async goodsSet() {
    const { ctx } = this;
    const { id, name } = ctx.request.body;
    await ctx.service.goods.goodsSet(id, name);
    ctx.body = {
      code: 200,
      msg: "更新成功",
    };
  }
}

module.exports = GoodsController;
